<template>
  <div>
    <!-- 顶部搜索框 -->
    <van-search
      v-model="value"
      placeholder="请输入小区或地址"
      show-action
      background="transparent"
    >
      <template #label>
        <div @click="$router.push('/citylist')">
          <span>{{ infocity.label }}</span> <i class="jo"></i>
        </div>
      </template>
      <template #action>
        <div>
          <van-icon
            name="location-o"
            size="20"
            color="white"
            @click="$router.push('/map')"
          />
        </div>
      </template>
    </van-search>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in images" :key="item.id">
        <img :src="ads + item.imgSrc" />
      </van-swipe-item>
    </van-swipe>
    <!-- middle导航 -->
    <van-grid :border="false" :icon-size="60">
      <van-grid-item to="/find" text="整租">
        <template #icon>
          <div>
            <van-icon name="wap-home-o" color="#2abb7f" size="50" />
          </div>
        </template>
      </van-grid-item>
      <van-grid-item to="/find" text="合租">
        <template #icon>
          <div>
            <van-icon name="friends-o" color="#2abb7f" size="50" />
          </div>
        </template>
      </van-grid-item>
      <van-grid-item to="/find" text="地图找房">
        <template #icon>
          <div>
            <van-icon name="location-o" color="#2abb7f" size="50" />
          </div>
        </template>
      </van-grid-item>
      <van-grid-item to="/find" text="去出租">
        <template #icon>
          <div>
            <van-icon name="shop-collect-o" color="#2abb7f" size="50" />
          </div>
        </template>
      </van-grid-item>
    </van-grid>
    <!-- 租房小组导航 -->
    <div class="group">
      <van-nav-bar left-text="租房小组" right-text="更多" />
      <van-grid
        :column-num="2"
        :gutter="10"
        direction="horizontal"
        :center="false"
        :clickable="true"
        :icon-size="50"
      >
        <van-grid-item
          v-for="item in images1"
          :key="item.id"
          :icon="ads + item.imgSrc"
        >
          <template #text>
            <div style="font-size: 14px; padding-left: 10px; color: #000">
              <p>{{ item.title }}</p>
              <p>{{ item.desc }}</p>
            </div>
          </template>
        </van-grid-item>
      </van-grid>
    </div>
  </div>
</template>

<script>
import { swiper, groups } from '@/api/home'
import { info } from '@/api/city'
// 设置本地存储首页默认城市
import { setInfoCity, getInfoCity } from '@/utils/storage'
export default {
  async created() {
    // console.log(JSON.parse(getInfoCity()))
    // 首页info城市信息请求
    setInfoCity(JSON.stringify(this.infocity))
    const infoObj = { name: this.infocity.label }
    const res2 = await info(infoObj)
    // console.log(res2.body)

    // 首页轮播图请求
    const res = await swiper()
    // console.log(res)
    this.images = res.body
    // console.log(this.images)
    // 租房小组请求

    const res1 = await groups(res2.body.value)
    this.images1 = res1.body
    // console.log(this.images1)
  },
  name: 'home-page',
  data() {
    return {
      value: '',
      images: [],
      ads: 'http://liufusong.top:8080',
      images1: [],
      infocity: JSON.parse(getInfoCity()) || {
        label: '深圳',
        value: 'AREA|a6649a11-be98-b150'
      }
    }
  }
}
</script>

<style lang="less" scoped>
// 搜索框 部分样式
.van-search {
  position: absolute;
  top: 15px;
  z-index: 2;
  width: 100%;
  // padding: 20px;
  // background: transparent;
  // 左侧小部分
  .van-search__label {
    padding: 0;
    margin-right: 10px;
    // border-right: 1px solid #ccc;
    .jo {
      position: relative;
      top: 12px;
      left: 3px;
      width: 0;
      height: 0;
      border: 4px solid transparent;
      border-top-color: #7f7f80;
    }
  }
  // 边框？
  /deep/ .van-icon-search {
    border-left: 1px solid #ccc;
    padding-left: 7px;
  }
}

// 轮播
.my-swipe .van-swipe-item {
  width: 100%;
  height: 212px;
  img {
    height: 100%;
  }
}
// middle导航
/deep/ .van-grid-item__icon {
  background-color: #f2fbf7;
  border-radius: 50%;
}
/deep/ .van-grid-item__icon-wrapper {
  margin-bottom: 10px;
  width: 60px;
  height: 60px;
  text-align: center;
  line-height: 90px;
  background-color: #f2fbf7;
  border-radius: 50%;
}
/deep/ .van-grid-item__text {
  font-size: 14px;
  color: #333;
}
// 租房小组
.group {
  padding-bottom: 10px;
  background-color: #f6f5f6;
  /deep/ .van-nav-bar__left .van-nav-bar__text {
    font-size: 15px;
    color: #333;
    font-weight: 700;
  }
  /deep/ .van-nav-bar__right .van-nav-bar__text {
    font-size: 14px;
    color: #787d82;
  }
}
</style>
